safari.self.browserWindow.addEventListener("command", toggleBar, false);
safari.self.browserWindow.addEventListener("validate", validateToggle, false);

//Allows bar to come and go as toolbar icon is clicked
function toggleBar(event) {
  //find out if it's visible right now
  var barState = safari.self.visible;
  
  //if it is visible, hide it
  if (barState == true) {
    safari.self.hide();
  }
  //if it is invisible, show it
  else {
    safari.self.show();
  }
}

//in case it's needed later
function validateToggle() {
  //nothing to validate right now
}

/************** DATA ARRAYS **************/
//Second Menu contents when "Blog" is selected in main menu
var blogMenuContents = ["The Entire SEC","Alabama","Arkansas","Auburn","Florida","Georgia","Kentucky","LSU","Ole Miss","Mississippi State","South Carolina","Tennessee","Vanderbilt"]

//Second Menu contents when "Roster" is selected in main menu
var rosterMenuContents = ["Alabama","Arkansas","Auburn","Florida","Georgia","Kentucky","LSU","Ole Miss","Mississippi State","South Carolina","Tennessee","Vanderbilt"]
/************** END DATA ARRAYS **************/

//Changes contents of second menu based on selected value in main menu
function editSecondMenu(value) {
  switch (value) {
    case 'blog':
	  clearSecondMenu();
      for (var i=0; i<blogMenuContents.length; i++) {
	    var newOption = document.createElement("option");
        newOption.text=blogMenuContents[i];
        newOption.value=blogMenuContents[i];    
        var targetMenu = document.getElementById("secondMenuSelect");		
        targetMenu.add(newOption);
	  }
	  break;
	case 'roster': 
	  clearSecondMenu();
      for (var i=0; i<rosterMenuContents.length; i++) {
	    var newOption = document.createElement("option");
        newOption.text=rosterMenuContents[i];
        newOption.value=rosterMenuContents[i];    
        var targetMenu = document.getElementById("secondMenuSelect");		
        targetMenu.add(newOption, null);
	  }
	  break;
	default: 
	  //nothing here, I suppose
  }
}

//clears out the Second Menu when the main menu changes
function clearSecondMenu() {
  var secondMen = document.getElementById("secondMenuSelect");
  secondMen.innerHTML = "";
}

//Where the magic of the Main/Second Menu combo happens
function submitMainMenu() {
  //grabbing Main Menu value
  var mainMen = document.getElementById("mainMenuSelect");
  var mainMenSel = mainMen.options[mainMen.selectedIndex].value;
  
  //grabbing Second Menu value
  var secondMen = document.getElementById("secondMenuSelect");
  var secondMenSel = secondMen.options[secondMen.selectedIndex].value;
  
  //let's do this
  switch (mainMenSel) {
    case 'blog':
	  safari.self.browserWindow.openTab('foreground', '9999');
	  switch (secondMenSel) {
	    case 'The Entire SEC':
		  safari.self.browserWindow.activeTab.url = 'http://www.teamspeedkills.com';
		break
		case 'Alabama':
		  safari.self.browserWindow.activeTab.url = 'http://www.rollbamaroll.com';
		break
		case 'Arkansas':
		  safari.self.browserWindow.activeTab.url = 'http://www.arkansasexpats.com';
		break
		case 'Auburn':
		  safari.self.browserWindow.activeTab.url = 'http://www.trackemtigers.com';
		break
		case 'Florida':
		  safari.self.browserWindow.activeTab.url = 'http://www.alligatorarmy.com';
		break
		case 'Georgia':
		  safari.self.browserWindow.activeTab.url = 'http://www.dawgsports.com';
		break
		case 'Kentucky':
		  safari.self.browserWindow.activeTab.url = 'http://www.aseaofblue.com';
		break
		case 'LSU':
		  safari.self.browserWindow.activeTab.url = 'http://www.andthevalleyshook.com';
		break
		case 'Ole Miss':
		  safari.self.browserWindow.activeTab.url = 'http://www.redcuprebellion.com';
		break
		case 'Mississippi State':
		  safari.self.browserWindow.activeTab.url = 'http://www.forwhomthecowbelltolls.com';
		break
		case 'South Carolina':
		  safari.self.browserWindow.activeTab.url = 'http://www.garnetandblackattack.com';
		break
		case 'Tennessee':
		  safari.self.browserWindow.activeTab.url = 'http://www.rockytoptalk.com';
		break
		case 'Vanderbilt':
		  safari.self.browserWindow.activeTab.url = 'http://www.anchorofgold.com';
		break
		default:
		  //nothing here, I suppose
	  }
	break
	case 'roster':
	  safari.self.browserWindow.openTab('foreground', '9999');
	  switch (secondMenSel) {
		case 'Alabama':
		  safari.self.browserWindow.activeTab.url = 'http://www.rolltide.com/sports/m-footbl/mtt/alab-m-footbl-mtt.html';
		break
		case 'Arkansas':
		  safari.self.browserWindow.activeTab.url = 'http://www.arkansasrazorbacks.com/ViewArticle.dbml?DB_OEM_ID=6100&ATCLID=204910367';
		break
		case 'Auburn':
		  safari.self.browserWindow.activeTab.url = 'http://auburntigers.cstv.com/sports/m-footbl/mtt/aub-m-footbl-mtt.html';
		break
		case 'Florida':
		  safari.self.browserWindow.activeTab.url = 'http://www.gatorzone.com/football/bios.php';
		break
		case 'Georgia':
		  safari.self.browserWindow.activeTab.url = 'http://www.georgiadogs.com/SportSelect.dbml?&DB_OEM_ID=8800&SPID=3571&SPSID=40675';
		break
		case 'Kentucky':
		  safari.self.browserWindow.activeTab.url = 'http://www.ukathletics.com/sports/m-footbl/mtt/kty-m-footbl-mtt.html';
		break
		case 'LSU':
		  safari.self.browserWindow.activeTab.url = 'http://www.lsusports.net/SportSelect.dbml?&DB_OEM_ID=5200&SPID=2164&SPSID=27812';
		break
		case 'Ole Miss':
		  safari.self.browserWindow.activeTab.url = 'http://www.olemisssports.com/SportSelect.dbml?&DB_OEM_ID=2600&SPID=737&SPSID=12787';
		break
		case 'Mississippi State':
		  safari.self.browserWindow.activeTab.url = 'http://www.mstateathletics.com/SportSelect.dbml?DB_OEM_ID=16800&KEY=&SPID=10997&SPSID=90891';
		break
		case 'South Carolina':
		  safari.self.browserWindow.activeTab.url = 'http://gamecocksonline.cstv.com/sports/m-footbl/mtt/scar-m-footbl-mtt.html';
		break
		case 'Tennessee':
		  safari.self.browserWindow.activeTab.url = 'http://www.utsports.com/sports/m-footbl/mtt/tenn-m-footbl-mtt.html';
		break
		case 'Vanderbilt':
		  safari.self.browserWindow.activeTab.url = 'http://vucommodores.cstv.com/sports/m-footbl/mtt/vand-m-footbl-mtt.html';
		break
		default:
		  //nothing here, I suppose
	  }
	break
	default:
	  //nothing here, I suppose
  }
}